package com.app.mymvp.business.login;

import android.os.Handler;

import com.app.mymvp.entity.UserInfoEntity;

/**
 * Created by HJ on 2016-10-10.
 */

public class LoginPresenter extends LoginContract.Presenter {
    private Handler mHandler = new Handler();
    @Override
    void login() {
        view.showLoading();
        model.login(view.getUserName(), view.getPassword(), new LoginContract.LoginListener() {
            @Override
            public void success(final UserInfoEntity userInfoEntity) {

                //需要在UI线程执行
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.toMainActivity(userInfoEntity);
                        view.hideLoading();
                    }
                });
            }

            @Override
            public void fail() {
                //需要在UI线程执行
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.showFailedError();
                        view.hideLoading();
                    }
                });
            }
        });
    }

    @Override
    void clear() {

    }
}
